package secondriver.jigsaw.logic;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import secondriver.jigsaw.R;
import android.graphics.Bitmap;

public class JigsawUtils {

	public static List<ImageGrid> spiltImage(Bitmap bitmap, int colums) {
		List<ImageGrid> list = new ArrayList<ImageGrid>();

		int width = bitmap.getWidth();
		int hegith = bitmap.getHeight();

		int imageEdge = Math.min(width, hegith) / colums;

		for (int y = 0; y < colums; y++) {
			for (int x = 0; x < colums; x++) {
				int index = x + colums * y;
				Bitmap bm = Bitmap.createBitmap(bitmap, x * imageEdge, y
						* imageEdge, imageEdge, imageEdge);
				list.add(new ImageGrid(index, bm));
			}
		}
		return list;
	}

	public static int[] images = new int[] { R.drawable.image0,
			R.drawable.image1, R.drawable.image2, R.drawable.image3,
			R.drawable.image4, R.drawable.image5, R.drawable.image6,
			R.drawable.image7, R.drawable.image8 };

	public static Random random = new Random();

	public static int getDrawable() {
		int index = random.nextInt(images.length);
		return images[index];
	}

	public static int getColumns(int level) {
		int columns = level + 2;
		return columns;
	}

	public static int getTimes(int level) {
		return (int) Math.pow(2, level) * 60;
	}

	public static int min(int... values) {
		int v = 0;
		for (int p : values) {
			if (v > p) {
				v = p;
			}
		}
		return v;
	}
}
